home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / basic / Mildred.lha / lha / BounceDemo.lha / Bounce.ascii < prev    next >
Text File  |  1998-11-25  |  3KB  |  144 lines

  1. WBStartup
  2.  
  3. ; Here is a demo of using MQSBlit to place queued cookie-cut objects behind
  4. ; a bitmap's stencil. Note that the unqueue does not take any notice of the stencil.
  5. ; You can substitute the MQSBlit with other things such as MQBlit, MQBlock, MQSBlock.
  6. ; Also if you take out the queue flush/unqueue line in the loop you can replace the
  7. ; MQSBlit with things like MBlit, MBlock, MTile32x32, MSBlit, etc.
  8.  
  9. ; Change this filepath to wherever the supplied pic is:
  10.  
  11. Pic$="Work:Test2/5Ms.IFF"
  12.  
  13.  
  14. #Width=320
  15. #Height=192
  16.  
  17. #Objects=40
  18.  
  19. #UnQ=-1 ; Wether or not to unqueue the objects
  20.  
  21. ;Init
  22. MCPU Processor        ; The two most important
  23. Mc2pCPUmode Processor ; lines in your program!
  24.  
  25. MReserveShapes 5
  26. MReserveBitmaps 2
  27. MReservec2pWindows 1
  28. MReserveQueues 1
  29.  
  30. Width.w=Max(#Width,320)
  31. Mc2pWindow 0,Width,#Height
  32.  
  33. InitBank 0,Width*#Height,$10002
  34. CludgeBitMap 0,Width,#Height,8,Bank(0)
  35. InitPalette 0,256
  36. Screen 0,0,0,Width,#Height,8,0,"Bounce",0,1,0
  37. LoadIFF Pic$,0,0
  38. ShowPalette 0
  39.  
  40. ;Make a chunky shape
  41. If MShape(0,64,64)=0 Then End
  42. For y=0 To 63
  43.   For x=0 To 63
  44.     MPlotShape x,y,Point(x,y)
  45.   Next x
  46. Next y
  47. MMakeCookie 0
  48.  
  49. s=1
  50. For y=0 To 32 Step 32
  51.   For x=0 To 32 Step 32
  52.     If MShape(s,32,32)=0 Then End
  53.     For yy=y To y+31
  54.       For xx=64+x To 64+x+31
  55.         MPlotShape xx MOD 32, yy MOD 32, Point(xx,yy)
  56.       Next xx
  57.     Next yy
  58.     MMakeCookie s
  59.     s+1
  60.   Next x
  61. Next y
  62.  
  63. ;Set up movement tables
  64. Dim x.w(#Objects)
  65. Dim y.w(#Objects)
  66. Dim xdirection.b(#Objects)
  67. Dim ydirection.b(#Objects)
  68. Dim xdirectionswap.b(#Objects)
  69. Dim ydirectionswap.b(#Objects)
  70. For obj=1 To #Objects
  71.   x(obj)=Rnd(Width-40)+8
  72.   y(obj)=Rnd(#Height-40)+8
  73.   Repeat
  74.     xdirection(obj)=Rnd(8)-4
  75.   Until xdirection(obj)<>0
  76.   Repeat
  77.     ydirection(obj)=Rnd(8)-4
  78.   Until ydirection(obj)<>0
  79.   xdirectionswap(obj)=-xdirection(obj)
  80.   ydirectionswap(obj)=-ydirection(obj)
  81. Next obj
  82.  
  83. ;Prepare
  84. If MBitmap(1,Width,#Height)=0 Then End
  85. MAutoStencil On
  86. If MBitmap(0,Width,#Height)=0 Then End
  87. MUseShape 0
  88. MClsStencil 0
  89. For yy=0 To #Height-64 Step 64
  90.   For xx=0 To Width-64 Step 64
  91.     MSBlock xx,yy
  92.   Next xx
  93. Next yy
  94. MUseBitmap 1
  95. MBlockScroll 0,0,Width,#Height,0,0,0
  96. MUseBitmap 0
  97.  
  98. MQSBlitCut On
  99. MSBlitCut On
  100. MQueue 0,#Objects
  101.  
  102. ;Loop
  103. its=0
  104. ResetTimer
  105. While Joyb(0)=0 AND Joyb(1)=0
  106.   For obj=1 To #Objects
  107.  
  108.     ;Move
  109.     x(obj)+xdirection(obj)
  110.     If x(obj)<4 OR x(obj)>Width-36 Then Exchange xdirection(obj),xdirectionswap(obj)
  111.     y(obj)+ydirection(obj)
  112.     If y(obj)<4 OR y(obj)>#Height-36 Then Exchange ydirection(obj),ydirectionswap(obj)
  113.  
  114.     ;Try changing this to a different type of blit. If it's not a Q-type blit, comment-out the unqueue line also
  115.     MQSBlit (obj MOD 4)+1,x(obj),y(obj) ; Stencil-cut blit and add to queue
  116.  
  117.   Next obj
  118.  
  119.   ;Display
  120.   Mc2p Bank(0) ; Display
  121.  
  122.   ;Comment this line out if not using a queued blit
  123.   If #UnQ Then MUnQueue 0,1 Else MFlushQueue 0
  124.  
  125.   its+1
  126. Wend
  127.  
  128. ;Report
  129. t=Timer
  130. t=Max(t,1)
  131. its=Max(its,1)
  132. a.q=50.0/(t/its)
  133. ScreenToBack_ Peek.l(Addr Screen(0))
  134. FindScreen 1
  135. Window 2,16,16,300,40,0,"Test results",1,0
  136. WindowOutput 2
  137. NPrint a," frames per second"
  138. NPrint " "
  139. NPrint "Press mouse/joy button..."
  140. Repeat
  141. Until Joyb(0)<>0 OR Joyb(1)<>0
  142.  
  143. End
  144.